from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from  jms.dim.dim_sys_network_detail_dt  import jms_dim__dim_sys_network_detail_dt
from  jms.dim.dim_lmdm_sys_staff import jms_dim__dim_lmdm_sys_staff
from jms.dim.dim_sys_manage_region import jms_dim__dim_sys_manage_region
from jms.dim.dim_lmdm_sys_area import jms_dim__dim_lmdm_sys_area
# from jms.ods.tms.yl_tmsnew_download_effective import jms_ods__yl_tmsnew_download_effective
from jms.dim.dim_lmdm_sys_special_time_limit_base import jms_dim__dim_lmdm_sys_special_time_limit_base
# from jms.dwd.tab.dwd_tab_barscan_sitesend_base_dt import jms_dwd__dwd_tab_barscan_sitesend_base_dt
# from jms.dwd.tab.dwd_tab_reback_transfer_express_base import jms_dwd__dwd_tab_reback_transfer_express_base
# from jms.dwd.tab.dwd_tab_barscan_sign_base_dt import jms_dwd__dwd_tab_barscan_sign_base_dt
# from jms.dwd.dwd_warhouse.dwd_wide_unsign_summary_waybill_dt import jms_dwd__dwd_wide_unsign_summary_waybill_dt
from jms.dwd.dwd_wide_abnormal_detail_waybill_dt import jms_dwd__dwd_wide_abnormal_detail_waybill_dt
# from jms.dwd.tab.dwd_tab_barscan_send_base_dt import jms_dwd__dwd_tab_barscan_send_base_dt
from jms.dim.dim_lmdm_sys_abnormal_piece import jms_dim__dim_lmdm_sys_abnormal_piece
from jms.dwd.tms.dwd_tmsnew_shipment_stop_union_base_dt import jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt
from jms.dwd.tab.dwd_tab_barscan_loading_base_dt import jms_dwd__dwd_tab_barscan_loading_base_dt
from jms.dim.ide.dim_jds_comatch_configuration_base import jms_dim__dim_jds_comatch_configuration_base
# from jms.time_sensor.time_after_03_00 import time_after_03_00
from jms.dim.dim_network_abnormal_type_union_dt import jms_dim__dim_network_abnormal_type_union_dt
from jms.dim.tms.dim_yl_tmsnew_download_effective_base import jms_dim__dim_yl_tmsnew_download_effective_base
from jms.dwd.dwd_terminal_back.dwd_terminal_send_dt_back import jms_dwd__dwd_terminal_send_dt_back
from jms.dwd.dwd_terminal_back.dwd_terminal_barscan_union_tmp_back import jms_dwd__dwd_terminal_barscan_union_tmp_back

jms_dwd__dwd_terminal_sign_all_detail_new_dt_back = SparkSqlOperator(
    task_id='jms_dwd__dwd_terminal_sign_all_detail_new_dt_back',
    task_concurrency=1,
    pool_slots=4,
    master='yarn',
    execution_timeout=timedelta(minutes=80),
    email=['rabie.zhuang@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dwd__dwd_terminal_sign_all_detail_new_dt_back_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dwd/dwd_terminal_back/dwd_terminal_sign_all_detail_new_dt_back/execute.sql',
    driver_memory='10G',
    driver_cores=4,
    executor_cores=12,
    executor_memory='12G',
    num_executors=100,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 130,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 300,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '6G',  # 堆外内存
          'spark.sql.shuffle.partitions': 3600,
          'spark.network.timeout': 900,
          'spark.core.connection.ack.wait.timeout': 300,
          'spark.sql.autoBroadcastJoinThreshold': 104857600,
          'spark.shuffle.io.maxRetries':'20',
          'spark.reducer.maxBlocksInFlightPerAddress':'3',
          'spark.shuffle.io.retryWait':'20',
          'spark.shuffle.memoryFraction': '0.8',
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=12'
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 50,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode': 50,  # 每天生成 20 个分区
              },
    yarn_queue='pro',
)
jms_dwd__dwd_terminal_sign_all_detail_new_dt_back <<[jms_dim__dim_sys_network_detail_dt,
                                                jms_dim__dim_lmdm_sys_staff,
                                                jms_dim__dim_sys_manage_region,
                                                jms_dim__dim_lmdm_sys_area,
                                                jms_dim__dim_lmdm_sys_special_time_limit_base,
                                                     jms_dwd__dwd_terminal_send_dt_back,

                                                jms_dwd__dwd_wide_abnormal_detail_waybill_dt,
                                                     jms_dwd__dwd_terminal_barscan_union_tmp_back,
                                                jms_dim__dim_lmdm_sys_abnormal_piece,
                                                jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt,
                                                jms_dwd__dwd_tab_barscan_loading_base_dt,
                                                jms_dim__dim_jds_comatch_configuration_base,

                                                jms_dim__dim_network_abnormal_type_union_dt,
                                                jms_dim__dim_yl_tmsnew_download_effective_base
                                                ]